const commentReducer = (state = {
	isFetching: false,
	items: []
}, action) => {
	switch (action.type) {
		case "RECEIVE_ARTICLE_COMMENT":
			return Object.assign({}, state, {
				items: action.items
			})
		case "POST_COMMENT_SUCCESS":
			return Object.assign({}, state, {
				items: [action.item, ...state.items]
			})
		case "POST_REPLY_SUCCESS":
			var _selfState = state;
			// 对副本进行深层操作
			for (var i = _selfState.items.length - 1; i >= 0; i--) {
				if (_selfState.items[i].comment_id == action.item.comment_id) {
					_selfState.items[i].reply.push(action.item)
				}
			}
			return Object.assign({}, state, {
				items: [..._selfState.items]
			})
		case "REQUEST_ERROR":
			return Object.assign({}, state, {
				info: action.info
			})
		default:
			return state
	}
}

export default commentReducer